[GLOBAL loader]
[EXTERN entry]
[EXTERN bootPgDir]

MODULEALIGN	EQU	1 << 0
MEMINFO		EQU	1 << 1
FLAGS		EQU	MODULEALIGN | MEMINFO
MAGIC		EQU	0x1BADB002
CHECKSUM	EQU	-(MAGIC + FLAGS)

[SECTION .text]
ALIGN	4
MultiBootHeader:
	DD	MAGIC
	DD	FLAGS
	DD	CHECKSUM

STACKSIZE	EQU	0x4000

loader:
	; Setup segment registers
	MOV	CX, 0x10
	MOV	DS, CX
	MOV	ES, CX
	MOV	FS, CX
	MOV	GS, CX
	MOV	SS, CX

	; Setup temporary stack
	MOV	ESP, (stack + 0x1000)
	
	PUSH	EAX
	PUSH	EBX
	
	FINIT

	LGDT	[GDTR]

	CALL	entry

Halt:
	JMP	Halt

[SECTION	.data]
GDT:
	DD	0
	DD	0
	
	DW	0xFFFF
	DW	0
	DB	0
	DB	0x9A
	DB	0xCF
	DB	0
	
	DW	0xFFFF
	DW	0
	DB	0
	DB	0x92
	DB	0xCF
	DB	0

GDTR:
	DW	23
	DD	GDT
	
[SECTION .bss]
ALIGN 32
stack:
	RESB	STACKSIZE

